#include "Temp.h";

extern LiquidCrystal lcd;

prog_char temp_probe_name_0[] PROGMEM = "Aquarium Temp";
prog_char temp_probe_name_1[] PROGMEM = "Water Change Temp";

PROGMEM const char *temp_probes_name_table[] = 
{   
  temp_probe_name_0,
  temp_probe_name_1
};

void Temp::init(){
  int address = EEPROM_TEMP_ADDRESS_START;
  for (int i = 0 ; i < TEMP_NUMBER_OF_PROBES ; ++ i ){
    temp_calibration_b[i] = EEPROM.read(address++) ;
    temp_calibration[ i ] =  get_calibration(    temp_calibration_b[i]  );
  }

  for (int i = 0 ; i < TEMP_NUMBER_OF_PROBES ; ++ i ){
    temp[i] = 25.5;
  }

}

void Temp::update_temp(){

}

float Temp::get_temp(byte probe_num){
  return temp[ probe_num ] + temp_calibration[ probe_num ];
}

char Temp::get_temp_calibration(byte probe_num){
  return temp_calibration_b[ probe_num ];
}

void Temp::set_temp_calibration(byte probe_num,char calibration){
  int address = EEPROM_TEMP_ADDRESS_START+probe_num;
  temp_calibration_b[ probe_num ] = calibration;
  temp_calibration[ probe_num ] =  get_calibration(calibration);
  EEPROM.write(address, calibration) ;
}

void Temp::print_temp(byte probe_num){
  lcd.print(temp[ probe_num ] + temp_calibration[ probe_num ] );
  lcd.print( (byte) 223 );
  lcd.print( "C" );
}

float Temp::get_calibration(char calibration){
  return ( (float)calibration ) / 10;   
}

void Temp::print_temp(byte probe_num,char calibration){
  lcd.print(temp[ probe_num ] +  get_calibration(calibration)  ) ;
  lcd.print( (byte) 223 );
  lcd.print( "C" );
}

void Temp::print_temp_without_calibration(byte probe_num){
  lcd.print(temp[ probe_num ] );
  lcd.print( (byte) 223 );
  lcd.print( "C" );
}

void Temp::print_temp_calibration(byte probe_num){
  lcd.print(temp_calibration[ probe_num ] );
  lcd.print( (byte) 223 );
  lcd.print( "C" );
}

void Temp::print_probe_name(byte probe_num){
  strcpy_P(buffer, (char*)pgm_read_word(&(  temp_probes_name_table[ probe_num ]     )));
  lcd.print(buffer );
}

float Temp::get_temp(byte temp_h,byte temp_l){
  float temp = temp_l;
  temp = temp / 100;
  temp+=  temp_h;
  return temp;
}

void Temp::print_temp(float temp){
  if(temp < 10){
    lcd.print( " " );
  }
  lcd.print(temp);
  lcd.print( (byte) 223 );
  lcd.print( "C" );
}

void Temp::print_temp(byte temp_h , byte temp_l){
  float temp = get_temp(temp_h,temp_l);
  print_temp(temp);
}











